﻿using UnityEngine;

namespace TC
{
    [Menu("Event/KeyDownEvent")]
    public class KeyDownEvent : EventNode
    {
        public KeyCode keyCode = KeyCode.Space;
        
        public ValueOutput<KeyCode> keyCodeOut;

        public override void OnCreate()
        {
            base.OnCreate();
            
            keyCodeOut = this.AddValueOutPort("KeyCode", () => { return keyCode; });
        }

        public override void Execute(Dispatcher chain)
        {
            base.Execute(chain);

            if (Input.GetKeyDown(keyCode))
            {
                chain.Call(flowOut);
            }
        }
    }
}
